package com.gdqy.FCS.web;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.gdqy.FCS.common.api.FastResponse;
import com.gdqy.FCS.common.api.ListResponse;
import com.gdqy.FCS.common.mvc.Args;
import com.gdqy.FCS.entity.Brand;
import com.gdqy.FCS.entity.DictionaryType;
import com.gdqy.FCS.service.DictionaryTypeService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

@Controller
@RequestMapping("dictionaryType")
public class DictionaryTypeController {
	
	@Autowired
	private DictionaryTypeService dictionaryTypeService;
	
	@RequestMapping("admin_dictionaryType")
	public ModelAndView admin_dictionaryType(Args args,int pageindex, int pagesize) {
		ModelAndView modelAndView = new ModelAndView();
		PageHelper.startPage(pageindex, pagesize);
		List<DictionaryType> dictionaryTypes = dictionaryTypeService.selectAll();
		PageInfo<DictionaryType> page = new PageInfo<DictionaryType>(dictionaryTypes);
		//分页对象
		ListResponse<DictionaryType> json= FastResponse._().errCode(0).subCode(0).errMsg("")
				.args(args.getReqeustargs()).pageIndex(page.getPageNum())
				.pageSize(page.getSize()).total((int)page.getTotal()).pageCount(page.getPages())
				.hasNext(page.isHasNextPage()).list(dictionaryTypes);
		
		modelAndView.addObject("json", json);
		modelAndView.setViewName("admin/dictionaryType");
		return modelAndView;
	}
	
	@RequestMapping("add_dictionaryType")
	public @ResponseBody String add_dictionaryType(DictionaryType dictionaryType) {
		String msg = "fail";
		int data = dictionaryTypeService.insert(dictionaryType);
		if(data>0) {
			msg="success";
		}
		return msg;
	}
	
}
